import type { App } from 'vue';
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { createWechatGuard } from './wechatGuard';
// import LAYOUT from '/@/components/LAYOUT.vue';

export const LAYOUT = () => import('/@/components/LAYOUT.vue');

const routes: Array<RouteRecordRaw> = [
  {
    path: '/:pompeiType?',
    name: 'detail',
    component: () => import('../views/detail.vue'),
    meta: {
      title: '详情',
      keepAlive: false,
    },
  },
  {
    path: '/home',
    name: 'Home',
    component: LAYOUT,
    redirect: '/home',
    meta: {
      title: '首页',
      keepAlive: false,
    },
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('/@/views/Home.vue'),
        meta: {
          title: '首页',
          keepAlive: false,
        },
      },
      {
        path: 'about',
        name: 'About',
        component: () => import('/@/views/About.vue'),
        meta: {
          title: '关于',
          keepAlive: false,
        },
      },
      {
        path: 'create',
        name: 'create',
        component: () => import('/@/views/create.vue'),
        meta: {
          title: '创建',
          keepAlive: false,
        },
      },

      {
        path: 'my',
        name: 'my',
        component: () => import('/@/views/my.vue'),
        meta: {
          title: '我的',
          keepAlive: false,
        },
      },
    ],
  },
  {
    path: '/createResult',
    name: 'createResult',
    component: () => import('/@/views/createResult.vue'),
    meta: {
      title: '创建结果',
      keepAlive: false,
    },
  },
  {
    path: '/intro/:uuid/:groupOpenid?',
    name: 'intro',
    component: () => import('/@/views/intro.vue'),
    meta: {
      title: '介绍',
      keepAlive: false,
    },
  },
  {
    path: '/show/:uuid?',
    name: 'show',
    component: () => import('../views/show/index.vue'),
    meta: {
      title: '详情',
      keepAlive: false,
    },
  },

  {
    path: '/join/:uuid/:groupOpenid?',
    name: 'join',
    component: () => import('/@/views/join.vue'),
    meta: {
      title: '加入',
      keepAlive: false,
    },
  },
  {
    path: '/joinResult',
    name: 'joinResult',
    component: () => import('/@/views/joinResult.vue'),
    meta: {
      title: '加入',
      keepAlive: false,
    },
  },

  {
    path: '/myCreateList',
    name: 'myCreateList',
    component: () => import('/@/views/myCreateList.vue'),
    meta: {
      title: '我创建的',
      keepAlive: false,
    },
  },
  {
    path: '/myJoinList',
    name: 'myJoinList',
    component: () => import('/@/views/myJoinList.vue'),
    meta: {
      title: '我加入的',
      keepAlive: false,
    },
  },
  {
    path: '/dataDetail/:uuid',
    name: 'dataDetail',
    component: () => import('/@/views/dataDetail.vue'),
    meta: {
      title: '详情',
      keepAlive: false,
    },
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

/**
 * vue-router配置
 * @param app
 */
export function setupRouter(app: App<Element>): void {
  app.use(router);
  // createWechatGuard(router);
}

export default router;
